Passed
Push — master ( 65f9b0...e165e5 )
by Eduardo
04:01
created

main.js ➔ startup   B

Complexity

Conditions 7

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 9
rs 8
c 0
b 0
f 0
cc 7
1
// jshint esversion: 8, -W104, -W069
2
3
const electron = require('electron'),
4
  url = require('url'),
5
  debug = require('debug')('main'),
6
  debugb = require('debug')('renderer'),
7
  fs = require('fs');
8
9
const {
10
  app,
11
  BrowserWindow,
12
  Menu,
13
  ipcMain,
14
  dialog,
15
  remote
16
} = electron;
17
18
require('./main/index');
19
20
var settings = require('./common/settings').load();
21
let mainWindow;
22
23
/*
24
  app.on('ready', function() {...}
25
    When application is ready
26
 */
27
app.on('ready', function() {
28
  const {
29
    'custom.configuration': configuration,
30
    'app.window': appWindow,
31
    'app.window.webPreferences': webPreferences,
32
    'app.window.url': appUrl
33
  } = settings;
34
35
  // Custom application settings startup
36
  if (fs.existsSync(app.getPath('userData') + configuration.filepath)) {
0 ignored issues
show
Bug introduced by
The variable configuration seems to be never declared. If this is a global, consider adding a /** global: configuration */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
37
    debug("Reading persistent configurations");
38
    settings = fs.readFile(app.getPath('userData') + configuration.filepath);
39
  } else {
40
    debug("Using default configurations");
41
  }
42
43
  // Some application start debugging messages
44
  debug("App is starting");
45
  debug("'appWindow.frame': {0}".format(appWindow.frame));
0 ignored issues
show
Bug introduced by
The variable appWindow seems to be never declared. If this is a global, consider adding a /** global: appWindow */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
46
  debug("'appWindow.height': {0}".format(appWindow.height));
47
  debug("'appWindow.width': {0}".format(appWindow.width));
48
49
  // mainWindow, Main application window initialization
50
  mainWindow = new BrowserWindow({
51
    frame: appWindow.frame, // Is basic frame shown (default: false)
52
    show: appWindow.show, // Show app before load (default: false)
53
    height: appWindow.height, // Window height in pixels (default: 700)
54
    width: appWindow.width, // Window width in pixels (default: 1000)
55
    icon: appWindow.icon, // App icon path (default: ...app.png)
56
    center: appWindow.center, // Center window
57
    minimizable: appWindow.minimizable, // Make window minimizable
58
    maximizable: appWindow.maximizable, // Make window maximizable
59
    movable: appWindow.movable, // Make window movable
60
    resizable: appWindow.resizable, // Make window resizable
61
    closable: appWindow.closable, // Make window closable
62
    focusable: appWindow.focusable, // Make window focusable
63
    alwaysOnTop: appWindow.alwaysOnTop, // Keep window on top
64
    fullscreen: appWindow.fullscreen, // Show window in fullscreen
65
    fullscreenable: appWindow.fullscreenable, // Make window able to go fullscreen
66
    kiosk: appWindow.kiosk, // Enable kiosk mode
67
    darkTheme: appWindow.darkTheme, // GTK dark theme mode
68
    thickFrame: appWindow.thickFrame, // Use WS_THICKFRAME style for frameless windows on Windows, which adds standard window frame. Setting it to false will remove window shadow and window animations.
69
    webPreferences: {
70
      nodeIntegration: webPreferences.nodeIntegration, // Enable node integration
0 ignored issues
show
Bug introduced by
The variable webPreferences seems to be never declared. If this is a global, consider adding a /** global: webPreferences */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
71
      zoomFactor: webPreferences.zoomFactor, // Page zoom factor
72
      image: webPreferences.image, // Image support
73
      experimentalFeatures: webPreferences.experimentalFeatures, // Enable Chromium experimental features
74
      backgroundThrottling: webPreferences.backgroundThrottling, // Whether to throttle animations and timers when the page becomes background
75
      offscreen: webPreferences.offscreen, // enable offscreen rendering for the browser window
76
      spellcheck: webPreferences.spellcheck, // Enable builtin spellchecker
77
      enableRemoteModule: webPreferences.enableRemoteModule // Enable remote module
78
    }
79
  });
80
81
  // mainWindow, Main window URL load
82
  mainWindow.loadURL(url.format({
83
    pathname: appUrl.pathname,
0 ignored issues
show
Bug introduced by
The variable appUrl seems to be never declared. If this is a global, consider adding a /** global: appUrl */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
84
    protocol: appUrl.protocol,
85
    slashes: appUrl.slashes
86
  }));
87
88
  // Some more debugging messages
89
  debug("'settings.url.protocol': {0}".format(appUrl.protocol));
90
  debug("'settings.url.pathname': {0}".format(appUrl.pathname));
91
  debug("'mainWindow' object: %o", mainWindow);
92
93
  /*
94
    mainWindow.once('ready-to-show', function() {...});
95
      Show main window when everything is ready
96
   */
97
  mainWindow.once('ready-to-show', function() {
98
    startup();
99
    debug('Showing main window');
100
    mainWindow.show();
101
  });
102
103
  /*
104
    mainWindow.on('closed', function() {...});
105
      Quit application when main window is closed
106
   */
107
  mainWindow.on('closed', function() {
108
    var {
109
      'app.window': appWindow
110
    } = settings;
111
112
    if (appWindow.closable) {
0 ignored issues
show
Bug introduced by
The variable appWindow seems to be never declared. If this is a global, consider adding a /** global: appWindow */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
113
      debug('Exiting application');
114
      app.quit();
115
    }
116
  });
117
});
118
119
/*
120
  startup
121
    Main thread startup checks
122
 */
123
function startup() {
124
  const {
125
    'startup': startup
126
  } = settings;
127
128
  debug('Doing startup checks');
129
  debug("'settings.startup.developerTools': {0}".format(startup.developerTools));
130
  if (startup.developerTools) mainWindow.toggleDevTools();
131
}
132
133
/*
134
  ipcMain.on('app:minimize', function() {...});
135
    Application minimize event
136
 */
137
ipcMain.on('app:minimize', function() {
138
  var {
139
    'app.window': appWindow
140
  } = settings;
141
  if (appWindow.minimizable) {
0 ignored issues
show
Bug introduced by
The variable appWindow seems to be never declared. If this is a global, consider adding a /** global: appWindow */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
142
    debug("App minimized");
143
    mainWindow.minimize();
144
  }
145
});
146
147
/*
148
  ipcMain.on('app:debug', function(...) {...});
149
    Application debug event
150
 */
151
ipcMain.on('app:debug', function(event, message) {
152
  debugb(message);
153
});
154